package com.example.demo.mapper;

import com.example.demo.model.Organization;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 组织架构数据访问接口
 */
@Mapper
public interface OrganizationMapper {
    
    @Select("SELECT * FROM organizations WHERE org_id = #{orgId}")
    Organization findById(@Param("orgId") Integer orgId);
    
    @Select("SELECT * FROM organizations WHERE parent_id = #{parentId}")
    List<Organization> findByParentId(@Param("parentId") Integer parentId);
    
    @Select("SELECT * FROM organizations WHERE org_type = #{orgType}")
    List<Organization> findByType(@Param("orgType") String orgType);
    
    @Select("SELECT * FROM organizations WHERE parent_id = #{parentId} AND org_type = #{orgType}")
    List<Organization> findByParentIdAndType(@Param("parentId") Integer parentId, @Param("orgType") String orgType);
    
    @Insert("INSERT INTO organizations(name, org_type, parent_id) VALUES(#{name}, #{orgType}, #{parentId})")
    @Options(useGeneratedKeys = true, keyProperty = "orgId")
    int insert(Organization organization);
    
    @Update("UPDATE organizations SET name = #{name}, org_type = #{orgType}, parent_id = #{parentId} WHERE org_id = #{orgId}")
    int update(Organization organization);
    
    @Delete("DELETE FROM organizations WHERE org_id = #{orgId}")
    int deleteById(@Param("orgId") Integer orgId);
    
    @Select("SELECT * FROM organizations")
    List<Organization> findAll();
} 